<?php
    $arrUser = $this->user;
?>
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
    <tr>
        <th rowspan="3" class="sized"><img src="/backend-store/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
        <th class="topleft"></th>
        <td id="tbl-border-top">&nbsp;</td>
        <th class="topright"></th>
        <th rowspan="3" class="sized"><img src="/backend-store/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
    </tr>
    <tr>
        <td id="tbl-border-left"></td>
        <td>
            <!--  start content-table-inner ...................................................................... START -->
            <div id="content-table-inner">

                <!--  start table-content  -->
                <div id="table-content">

                    <!--  start product-table ..................................................................................... -->
                    <form id="mainform" action="">
                        <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
                            <tr>
                                <th class="table-header-check"><a id="toggle-all" ></a> </th>
                                <th class="table-header-repeat line-left"><a href="">UserName</a></th>
                                <th class="table-header-repeat line-left"><a href="">Fullname</a></th>
                                <th class="table-header-repeat line-left"><a href="">Email</a></th>
                                <th class="table-header-repeat line-left"><a href="">Phone No</a></th>
                                <th class="table-header-repeat line-left"><a href="">Status</a></th>
                                <th class="table-header-options line-left"><a href="">Action</a></th>
                            </tr>
                            <?php
                                if(!empty($arrUser)) :
                                    foreach($arrUser as $key => $val) :
                                        $status = NULL;
                                        if($val['status']==0) {
                                             $status = 'InActived';
                                             $action = 'Normal?';
                                             $valAction = 1;
                                        }
                                        elseif($val['status']==1) {
                                            $status = 'Normal';
                                            $action = 'Pending?';
                                            $valAction = 2;
                                        }
                                        elseif ($val['status']==2) {
                                            $status = 'Pending';
                                            $action = 'Lock?';
                                            $valAction = 3;
                                        }
                                        elseif($val['status']==3) {
                                            $status = 'Locked';
                                            $action = 'Locked';
                                            $valAction = 10;
                                        }
                            ?>
                            <tr>
                                <td><input  type="checkbox"/></td>
                                <td><?=$val['username']?></td>
                                <td><?=$val['fullname']?></td>
                                <td><?=$val['email']?></td>
                                <td><?=$val['cellphone']?></td>
                                <td><?=$status?></td>
                                <td class="options-width" align="center">
                                    <strong>
                                    <a href="javascript:void(0)" onclick="updateuser(<?=$val['userid']?>, 1)" title="Set Normal" >Set Normal</a> |
                                    <a href="javascript:void(0)" onclick="updateuser(<?=$val['userid']?>, <?=$valAction?>)" title="Set <?=$action?>" ><?=$action?></a>
                                    </strong>
                                </td>
                            </tr>
                            <?php
                                    endforeach;
                                endif;
                            ?>
                        </table>
                        <!--  end product-table................................... -->
                    </form>
                </div>
                <!--  end content-table  -->

                <div class="clear"></div>

            </div>
            <!--  end content-table-inner ............................................END  -->
        </td>
        <td id="tbl-border-right"></td>
    </tr>
    <tr>
        <th class="sized bottomleft"></th>
        <td id="tbl-border-bottom">&nbsp;</td>
        <th class="sized bottomright"></th>
    </tr>
</table>

<script type="text/javascript">
    $( function(){
        updateuser = function(userid, status) {
            if(status == 10) {
                return;
            }

            if (confirm('Bạn có muốn thay đổi trạng thái?')) {
                $.ajax({
                    type: "POST",
                    url: "/backend/account/updatestatus",
                    data: {userid:userid, status:status},
                    success: function(data){
                        window.location.href = '/backend/account/get';
                    }
                });
            }
            
            return;
        }
    });
</script>